<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ComboList.aspx.cs" Inherits="ComboList" Title="ABC SuperSign - Combo List" %>
<%@ Register Src="UserAccess.ascx" TagName="UserAccess" TagPrefix="uc1" %>
<%@ Register Src="GlobalAjax.ascx" TagName="GlobalAjax" TagPrefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder_Main" Runat="Server">
<form id="Form_ComboList" runat="server"> 
<asp:HiddenField ID="Hidden_BtnChoice" runat="server" />    
<asp:ScriptManager ID="ScriptManager_ComboList" runat="server">
</asp:ScriptManager> 

<uc2:GlobalAjax ID="ctl_GlobalAjax" runat="server" />

<!-- page title start -->
<h1>
    <span>Combo List</span>
	<asp:Button ID="Btn_New" runat="server" Text="Create New Combo" CssClass="aspButton" PostBackUrl="~/Editor.aspx" OnClick="Btn_New_Click" />
</h1>
<!-- page title end -->
<!-- main content start -->
<div class="mainHolder">
     <!-- left block start -->
    <div class="leftBlock">
	    <h2>
		    <span>Search Combos</span>
	    </h2>
		<div class="innerContent">
            <div id="comboList_SearchFields"></div>
		    <div id="comboSearchButtons" class="row" style="display:none;">
                <asp:Button ID="Btn_Search" runat="server" Text="Search" OnClientClick="prepareSearch();" OnClick="Btn_Search_Click" />
                <div class="spacerS"></div>
	            <input id="comboReset" type="button" value="Reset" onclick="resetSearchFields('comboList_SearchFields');"/>
	        </div>
	    </div>
    </div>
    <!-- left block end -->
    <!-- right block start -->
    <div class="rightBlock">
	    <h2>
		    <span>Search Results</span>
	    </h2>
        <div class="innerContent">
        <asp:UpdatePanel ID="UpdatePanel_Alerts" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Btn_Search" EventName="Click" />
        </Triggers>
        <ContentTemplate>
            <div class="row">
                <asp:Label ID="Label_ComboAlerts" runat="server" Text=""></asp:Label>
            </div>
        </ContentTemplate>
        </asp:UpdatePanel>
        <div class="row">
        <asp:UpdatePanel ID="UpdatePanel_Details" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Btn_Search" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="DDList_Sort" EventName="SelectedIndexChanged"></asp:AsyncPostBackTrigger>
        </Triggers>
        <ContentTemplate>
		    <div class="col widthXM">
		        <div class="row">
			        <label class="big">
				        <span>Combos</span>
			        <asp:DropDownList id="DDList_Sort" runat="server" AutoPostBack="true" CssClass="small right" OnSelectedIndexChanged="DDList_Sort_SelectedIndexChanged">
                    <asp:ListItem value="0" text="Sort By" />
                    <asp:ListItem value="1" text="Name" />
                    <asp:ListItem value="2" text="Newest" />
                </asp:DropDownList> 
			        </label>
		        </div>
		        <div class="row">
                    <asp:ListBox ID="ListBox_Results" runat="server" CssClass="heightL widthXM"></asp:ListBox>                    
	            </div>
		    </div>
		    <div class="spacerXL"></div>
		    <div class="col">
			    <div class="row">
			        <label class="big">Combo Info</label>
			    </div>
			    <div class="row">
                    <asp:Panel ID="Panel_ComboInfo" runat="server" CssClass="aspPanel heightM widthXM">
                        <asp:Label ID="NameLabel" runat="server" Text=""></asp:Label>
                    </asp:Panel>
                </div>
		    </div>
		</ContentTemplate>
        </asp:UpdatePanel>
		    <div class="spacerXL"></div>
		    <div class="col">
		        <div class="row">
			        <label>&nbsp;</label>
			    </div>
			    <div class="row">
			        <asp:Button ID="Btn_Edit" runat="server" Text="Edit Selected Combo" CssClass="widthM" PostBackUrl="~/Editor.aspx" OnClick="Btn_Edit_Click" />
			    </div>
                <div id="btnDuplicateRow" class="row" style="display:none;">
                    <input type="button" id="btnDuplicate" disabled="disabled" class="widthM" value="Duplicate Combo As..." onclick="prepareDuplicateAs();" />
                </div>
                <div id="btnDisableRow" class="row" style="display:none;">
                    <input type="button" id="btnDisable" disabled="disabled" class="widthM" value="Disable Combo" onclick="prepareDisable();" />
                </div>
                <div id="btnEnableRow" class="row" style="display:none;">
                    <input type="button" id="btnEnable" disabled="disabled" class="widthM" value="Enable Combo" onclick="prepareEnable();" />
                </div>
                <div class="row">
                <br />
                <br />
                </div>
                <div class="row">
                    <asp:Label ID="Lbl_DefaultCombo" runat="server">Default Combos</asp:Label>
                </div>
                <asp:UpdatePanel ID="UpdatePanel_DefaultList" runat="server" UpdateMode="Conditional">
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="DropDown_DefaultCombo" EventName="SelectedIndexChanged" />
                    </Triggers>
                    <ContentTemplate>
                <div class="row">
                    <asp:DropDownList id="DropDown_DefaultCombo" CssClass="widthM" runat="server" OnSelectedIndexChanged="DropDown_DefaultCombo_SelectedIndexChanged"></asp:DropDownList>
                </div>
                </ContentTemplate>
                </asp:UpdatePanel>
                <div class="row">
                    <asp:Button ID="Btn_EditDefaultCombo" runat="server" Text="Edit Selected Default Combo" CssClass="widthM" PostBackUrl="~/Editor.aspx" OnClick="Btn_EditDefaultCombo_Click" />
                </div>
		    </div>
        </div>
	    </div>
    </div>
    <!-- right block end -->
</div>
<!-- main content end -->

<script type="text/javascript">
    document.onclick =  function () {
            $('<%= Label_ComboAlerts.ClientID %>').style.display = "none";
        }
        
    function loadComboSearchFields () {
    	
        // make calls to load search params              
        var sProc = "<STOREDPROCEDURE Name=\"sproc_WEB_GetSearchFields\" Level=\"3\" />";
        callAjaxPost(eventSFRequest, sProc, processEventSFRequestChange);
        
        sProc = "<STOREDPROCEDURE Name=\"sproc_WEB_GetSearchFields\" Level=\"4\" />";
        callAjaxPost(comboSFRequest, sProc, processComboSFRequestChange); 
   
    }
    activeEditorPageId = "comboList";
    loadComboSearchFields(); 

    // event handler for index change on selected listbox
    function selectedIndexChange() {
        var selectList = $('<%= ListBox_Results.ClientID %>');
        // request info for selected item
        requestGetInfo(selectList.options[selectList.selectedIndex].value, 3, $('<%= Panel_ComboInfo.ClientID %>'));
        if (selectList.selectedIndex != -1) {
            $('<%= Btn_Edit.ClientID %>').removeAttribute('disabled');
            $('btnDuplicate').removeAttribute('disabled');
            if (selectList.options[selectList.selectedIndex].hasClassName('disabledOption')) {
                $('btnDisable').setAttribute('disabled', 'disabled');
                $('btnEnable').removeAttribute('disabled');
            } else {
                $('btnDisable').removeAttribute('disabled');
                $('btnEnable').setAttribute('disabled', 'disabled');
            }
        } 
    }
    
    // event handler for search click
    function searchClick() {
        $('<%= Btn_Edit.ClientID %>').setAttribute('disabled', 'disabled');
        $('btnDuplicate').setAttribute('disabled', 'disabled');
        $('btnDisable').setAttribute('disabled', 'disabled');
        $('btnEnable').setAttribute('disabled', 'disabled');
    }
    
    // function to prepare duplicate as popup
	function prepareDuplicateAs() {
	    var selectList = $('<%= ListBox_Results.ClientID %>');
        var name = selectList.options[selectList.selectedIndex].text;
        var dbId = selectList.options[selectList.selectedIndex].value;
        var msgNode = $('<%= Label_ComboAlerts.ClientID %>');
        $('dupAlert').style.display = "none";
	    showDuplicateAs('combo', name, dbId, msgNode);
	}   
	
	// function to prepare call to disable object
	function prepareDisable() {
	    var selectList = $('<%= ListBox_Results.ClientID %>');
        var dbId = selectList.options[selectList.selectedIndex].value;
        var msgNode = $('<%= Label_ComboAlerts.ClientID %>');
	    requestEnableDisable(dbId, 3, false, msgNode)
	}
	
	// function to prepare call to enable object
	function prepareEnable() {
	    var selectList = $('<%= ListBox_Results.ClientID %>');
        var dbId = selectList.options[selectList.selectedIndex].value;
        var msgNode = $('<%= Label_ComboAlerts.ClientID %>');
	    requestEnableDisable(dbId, 3, true, msgNode)
	}    
	
	// function to prepare search
	var comboSearchRequest = null;
	function prepareSearch() {
	    comboSearchRequest = new XMLHttpRequest();
        $('pageContainer').addClassName('fadedBG');
        $('searchingMsg').style.display = "block";
        // add values to search xml 
        addSearchValuesToXML();  

        var url = "ListSearchPost.aspx";
        comboSearchRequest.open('POST', url, false);
        comboSearchRequest.setRequestHeader("Content-Type", "text/xml");
        comboSearchRequest.send(sfXML);
        if (comboSearchRequest.readyState == 4) {
		    if (comboSearchRequest.status == 200) {
		        $('pageContainer').removeClassName('fadedBG');
	            $('searchingMsg').style.display = "none";
		        return;
		    }
		}
	}

</script>
<uc1:UserAccess ID="UserAccess2" runat="server" />
</form>
</asp:Content>

